#coding:utf8
from rest_framework import serializers
from .models import Area


class AreaSerializer(serializers.ModelSerializer):
    """
    序列化器

    [{'id:1,'name':'xxxx'},{'id:1,'name':'xxxx'}{'id:1,'name':'xxxx'}]
    """
    class Meta:
        model = Area
        fields = ['id','name']

# ['id':xxx,'name':xxx,'subs': [[{'id:1,'name':'xxxx'},{'id:1,'name':'xxxx'}{'id:1,'name':'xxxx'}]]
class SubAreaSerializer(serializers.ModelSerializer):

    #related_name='subs'
    #因为我设置了 修改 关联模型 的名字
    # area_set = AreaSerializer(many=True,read_only=True)
    subs = AreaSerializer(many=True, read_only=True)

    class Meta:
        model = Area
        fields = ('id', 'name', 'subs')


# 书籍

# 1       三国演义

# 人物信息

#11     刘备      1
#22     刘寻得      1
#33     刘xxx     1
